<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ page import="wpmp.security.client.utils.UserUtils"%>
<%@ page import="wpmp.security.client.utils.ButtonConfigUtils"%>
<%@ page import="wpmp.portal.Configurations"%>
<%@ include file="/commons/taglibs.jsp"%>
<html>
<head>
<title>wpmp-main</title>
<%@ include file="/commons/meta.jsp" %>
<%@ include file="/commons/header.jsp" %>
<%@ include file="/ext3/import.jsp" %>
<%@ include file="/easyext3/import.jsp" %>
<script type="text/javascript" src="${ctx }/easyext3/src/tool/VTypes.js"></script>
<style type="text/css">
.main-header {
    background: url(<%=Configurations.getMainHeaderBackgroundUrl()%>) no-repeat center;
}
.main-footer {
	text-align: center;
	font-family: "微软雅黑";
	font-size: 12px;
	color: #026e62;
}
</style>
<script language="javascript" type="text/javascript">
var sid = '${sid}';

function getCurrentPosition(node){
	var path=node.getPath('text');
	if (Ext.isEmpty(path)){
		return '';
	}
	return path.substr(1).replace(/\//g,' >> ');
}

function spliceParaUrl(url,paraUrl) {
	if(!paraUrl){
		return url;
	}
	paraUrl=paraUrl.replace(/\+/g,'%2B');
	var sw=(paraUrl.charAt(0)==='&');
	var index=url.indexOf("?");
	if(index==-1){
		if(sw){
			return url+'?'+paraUrl.substring(1);
		}else{
			return url+'?'+paraUrl;
		}
	}else{
		var ec=url.charAt(url.length-1);
		if(ec==='?'||ec==='&'){
			if(sw){
				return url+paraUrl.substring(1);
			}else{
				return url+paraUrl;
			}
		}else{
			if(sw){
				return url+paraUrl;
			}else{
				return url+'&'+paraUrl;
			}
		}
	}
}

function logoutSystem(){
	Ext.Msg.confirm('','确认注销用户？',function (flag) {
		if(flag!='yes') return;
		Ext.Msg.wait('正在注销用户, 请稍候 ... ...');
		Ext.Ajax.request({
			url: '${ctx}/logout.do',
			callback: function(options, success, response){
				var result=Ext.decode(response.responseText);
				EasyExt.parse(result, function(buttonId){
					Ext.Msg.hide();
					if (result.pass || buttonId=='yes') {
						window.location.href='${ctx}/index.do';
					}
				});
			}
		});
	});
}
var updatePasswordWindow = new Ext.Window({
	title:'修改密码',
	resizable:true,
	width:320,
	height:180,
	layout:'fit',
	modal:true,
	autoDestroy:true,
	autoShow:true,
	closeAction:'hide',
	items:{
		layout:'form',
		xtype:'form',
		bodyStyle:'padding-top:5px;',
		border:false,
		labelAlign:'right',
		labelWidth:70,
		defaultType:'textfield',
		defaults:{
			allowBlank:false,
			validateOnBlur:false,
			anchor:'90%',
			msgTarget:'qtip',
			inputType:'password',
			maxLength:16,
			minLength:6
		},
		items:[{
			fieldLabel: '原密码',
			name: 'password'
		},{
			fieldLabel: '新密码',
			name:'newPassword',
			vtype: 'password',
			id: 'J-921b9a45f08f4fe6b30b3f25027b0e54'
		},{
			fieldLabel: '确认密码',
			name: 'confirmPassword',
			vtype: 'password',
			initialPassField: 'J-921b9a45f08f4fe6b30b3f25027b0e54'
		}]
	},
	buttonAlign:'center',
	buttons:[{
		text:'保存',
		handler:function(thiz,eventObj){
			if(!updatePasswordWindow.get(0).getForm().isValid()){
				return;
			}
			
			updatePasswordWindow.get(0).getForm().doAction('submit',{
				url: '${ctx}/updatePassword.do',
				method: 'post',
				waitTitle: ' ',
			    waitMsg: '正在提交数据, 请稍候 ... ...',
				params: {},
				success: function(form, action) {
					var result = action.result;
					EasyExt.parse(result, function(buttonId){
						Ext.Msg.hide();
						updatePasswordWindow.hide();
					});
				},
		        failure: function(form, action){
		        	Ext.Msg.alert('系统提示',action.result.msg);
		        }
			});
		}
	},{
		text:'取消',
		handler: function(thiz,eventObj){
			updatePasswordWindow.hide();
		}
	}],
	listeners:{
		show:function(thiz) {
			thiz.get(0).get(0).focus(true, 500);
		},
		hide:function(thiz){
			thiz.get(0).form.reset();
		}
    }
});

function updatePassword(){
	updatePasswordWindow.show();
}

Ext.onReady(function() {
    
	var viewport=new Ext.Viewport({
		layout: 'border',
		items: [{
			region: 'north',
			height: 45,
			xtype: 'panel',
			border: false,
			bodyCssClass: 'main-header',
			html: '<table style="" width="100%" height="100%" border=0>'+
					'<tr>'+
					'<td style="padding:5 0 0 50;font-size:30;font-weight:500;" rowspan=2 align="left">'+
					'</td>'+
					'<td align="right" style="font-size:13;padding:5 12 0 0;">'+
					'<div><%if(!ButtonConfigUtils.hidden(request, response, "main.updatePassword")){%><a href="javascript:void(0)" onclick="updatePassword()" style="text-decoration:none;">修改密码</a>&nbsp;|<%}%>&nbsp;<a href="javascript:void(0)" onclick="logoutSystem();" style="text-decoration:none;">退出</a></div>'+
					'</td>'+
					'</tr>'+
					'<tr>'+
					'<td align="right" style="font-size:13;padding:0 12 5 0;">'+
					'欢迎您:&nbsp;<%=UserUtils.getUserName(request)%>'+
					'</td>'+
					'</tr>'+
					'</table>'
		},
		{
			region: 'south',
			height: 16,
			layout: 'fit',
			xtype: 'box',
			html: '<div class="main-footer"><%=Configurations.getMainFooterText()%>&nbsp;©&nbsp;2013</div>'
		},
		{
			xtype: 'tabpanel',
			region: 'center',
			activeTab: 0,
			enableTabScroll: true,
			items: [${centerHtml}]
		}]
	});
});
</script>
</head>
<body>
</body>
</html>